package com.xizhi.zomprogress.controller;


import com.xizhi.zomprogress.bean.User;
import com.xizhi.zomprogress.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 * @author xiaomin
 * @date 2018/11/5
 */

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;
    //获取全部数据
    @RequestMapping("/getAllUser")
    @ResponseBody
    public List<User> getAllUser() {
        return userService.selectAllUsers();

    }
    //通过邀请，新增用户
    @RequestMapping("/addUser")
    @ResponseBody
    public int addUser(
                                 @RequestParam String userName,
                                 @RequestParam String userImage,
                                 @RequestParam String invitedUser,
                                 @RequestParam String signedUser,
                                 @RequestParam String alreadyObtain
                     ) {
       List<User> list  = userService.cheakRepeatUser(userName,invitedUser);
        if (!list.isEmpty()){
            return 0;
        }
        return userService.addUser(userName,userImage,invitedUser,signedUser,alreadyObtain);
    }
   //获取邀请列表
    @RequestMapping("/getUserByInvitedUser")
    @ResponseBody
    public List<User>  getUserByInvitedUser(
                                 @RequestParam String invitedUser) {
        return userService.getUserByInvitedUser(invitedUser);

    }
    //检查重复添加
    @RequestMapping("/cheakRepeatUser")
    @ResponseBody
    public List<User> cheakRepeatUser(@RequestParam String userName,
                                        @RequestParam String invitedUser
                                       ) {
        return userService.cheakRepeatUser(userName,invitedUser);
    }

   //获得领砖石的邀请列表  signedUser =no (没有领取)  signedUser =yes (已经领取)
   @RequestMapping("/getSiginUserList")
   @ResponseBody
   public List<User> getSiginUserList(@RequestParam String invitedUser,
                                     @RequestParam String signedUser
   ) {
       return userService.getSiginUserList(invitedUser,signedUser);
   }

    //领取砖石接口
    @RequestMapping("/diamondSign")
    @ResponseBody
    public int diamondSign(@RequestParam Integer id,
                           @RequestParam String signedUser) {
        return userService.diamondSign(signedUser,id);

    }

}
